<template>
	<el-card class="form-container">
		<el-form :model="dataForm" ref="dataForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="90px">
			<el-form-item label="订单支付超时关闭时间(分)" prop="orderPayOvertime">
				<el-input v-model="dataForm.orderPayOvertime" placeholder="请输入订单支付超时关闭时间(分)"></el-input>
			</el-form-item>
			<el-form-item label="正常订单超时时间(分)" prop="normalOrderOvertime">
				<el-input v-model="dataForm.normalOrderOvertime" placeholder="请输入正常订单超时时间(分)"></el-input>
			</el-form-item>
			<el-form-item label="发货后自动确认收货时间（天）" prop="confirmOvertime">
				<el-input v-model="dataForm.confirmOvertime" placeholder="请输入发货后自动确认收货时间（天）"></el-input>
			</el-form-item>
			<el-form-item label="自动完成交易时间，不能申请售后（天）" prop="finishOvertime">
				<el-input v-model="dataForm.finishOvertime" placeholder="请输入自动完成交易时间，不能申请售后（天）"></el-input>
			</el-form-item>
			<el-form-item label="订单完成后自动好评时间（天）" prop="commentOvertime">
				<el-input v-model="dataForm.commentOvertime" placeholder="请输入订单完成后自动好评时间（天）"></el-input>
			</el-form-item>
			<el-form-item label="拼团订单超时关闭时间(小时)" prop="assembleOrderOvertime">
				<el-input v-model="dataForm.assembleOrderOvertime" placeholder="请输入拼团订单超时关闭时间(小时)"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" @click="submit('dataForm')">确定</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	import {
		createOrderConfig
	} from '@/api/admin/orderConfig'
	export default {
		name: 'add-orderConfig',
		data() {
			return {
				dataForm: {
					orderPayOvertime: ''
					normalOrderOvertime: ''
					confirmOvertime: ''
					finishOvertime: ''
					commentOvertime: ''
					assembleOrderOvertime: ''
				},
				dataRule: {
					orderPayOvertime: [{
							required: true,
							message: '请输入订单支付超时关闭时间(分)',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 20,
							message: '长度在 3 到 20 个字符',
							trigger: 'blur'
						}
					]
					normalOrderOvertime: [{
							required: true,
							message: '请输入正常订单超时时间(分)',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 20,
							message: '长度在 3 到 20 个字符',
							trigger: 'blur'
						}
					]
					confirmOvertime: [{
							required: true,
							message: '请输入发货后自动确认收货时间（天）',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 20,
							message: '长度在 3 到 20 个字符',
							trigger: 'blur'
						}
					]
					finishOvertime: [{
							required: true,
							message: '请输入自动完成交易时间，不能申请售后（天）',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 20,
							message: '长度在 3 到 20 个字符',
							trigger: 'blur'
						}
					]
					commentOvertime: [{
							required: true,
							message: '请输入订单完成后自动好评时间（天）',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 20,
							message: '长度在 3 到 20 个字符',
							trigger: 'blur'
						}
					]
					assembleOrderOvertime: [{
							required: true,
							message: '请输入拼团订单超时关闭时间(小时)',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 20,
							message: '长度在 3 到 20 个字符',
							trigger: 'blur'
						}
					]
				}
			}
		},
		methods: {
			cancel() {
				this.$router.go(-1)
			},
			submit() {
				const set = this.$refs;
				set['dataForm'].validate((valid) => {
					if (!valid) {
						return false
					}
					createOrderConfig(this.dataForm).then(() => {
						this.$notify({
							title: '添加成功',
							message: '添加成功',
							type: 'success',
							duration: 2000,
							onClose: this.$router.go(-1)
						})
					})
				})
			}
		}
	}
</script>

<style>
</style>
